package com.jader.adapter;

import java.util.List;

import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.NetworkImageView;

import com.jader.beans.Goods;
import com.jader.util.JaderApplication;
import com.zlp.jader.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class Adapter_listview_pic extends BaseAdapter {
	List<Goods> list;
	private Context context;
	private LayoutInflater mInflater;
	private ViewHoder viewholder;
	private ImageLoader imageLoader;

	public Adapter_listview_pic(List<Goods> list, Context context,
			ImageLoader imageLoader) {
		super();
		this.list = list;
		this.context = context;
		this.imageLoader = imageLoader;
		mInflater = LayoutInflater.from(this.context);
	}

	@Override
	public int getCount() {

		return list.size();
	}

	@Override
	public Object getItem(int arg0) {

		return list.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {

		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		// 装入每一行的布局文件
		if (arg1 == null) {
			arg1 = mInflater.inflate(R.layout.adapter_ding_detail_item, null);
			viewholder = new ViewHoder();
			viewholder.imageView = (NetworkImageView) arg1
					.findViewById(R.id.ding_adapter_list_pic);
			viewholder.descTextView = (TextView) arg1
					.findViewById(R.id.ding_ders);
			viewholder.priceTextView = (TextView) arg1
					.findViewById(R.id.specific_price);
			viewholder.saletTextView = (TextView) arg1
					.findViewById(R.id.sale_num);
			arg1.setTag(viewholder);
		}
		viewholder = (ViewHoder) arg1.getTag();
		// 图片 描述 价格 销量
		viewholder.imageView.setImageUrl(
				JaderApplication.getIP() + list.get(arg0).getPicture(),
				imageLoader);
		viewholder.descTextView.setText(list.get(arg0).getDesc());
		viewholder.priceTextView.setText(list.get(arg0).getPrice() + "");
		viewholder.saletTextView.setText(list.get(arg0).getNumber());
		// 返回布局视图
		return arg1;

	}

	// 缓存类
	class ViewHoder {
		// 初始化控件
		NetworkImageView imageView;
		TextView descTextView, priceTextView, saletTextView;

	}
}
